package com.jinglvhuanjing.app.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.jinglvhuanjing.app.R;
import com.jinglvhuanjing.app.bean.param.ParamLayout4Bean;
import com.jinglvhuanjing.app.listener.ButtonClickEvent;

import java.util.ArrayList;
import java.util.HashMap;

public class ParamSettingRow4View extends ConstraintLayout {

    public ParamSettingRow4View(@NonNull Context context) {
        super(context);
        this.init(context);
    }

    public ParamSettingRow4View(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.init(context);
    }

    public ParamSettingRow4View(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init(context);
    }

    /*** 满溢数值 ***/
    private ParamSettingTermView device_working_status_myxz;
    /*** 电机位置 ***/
    private ParamSettingTermView device_working_status_djwz;
    /*** 电机电流 ***/
    private ParamSettingTermView device_working_status_djdl;
    /*** 感应信号 ***/
    private ParamSettingTermView device_working_status_gyxh;
    /*** 称重数据 ***/
    private ParamSettingTermView device_working_status_czsj;
    /*** 设备按钮1 ***/
    private ButtonView device_button_1;
    /*** 设备按钮2 ***/
    private ButtonView device_button_2;
    /*** 设备按钮3 ***/
    private ButtonView device_button_3;
    /*** 设备按钮4 ***/
    private ButtonView device_button_4;
    /*** 设备按钮5 ***/
    private ButtonView device_button_5;

    private void init(Context context) {

        LayoutInflater.from(context).inflate(R.layout.view_params_setting_row_4_layout, this, true);
        this.device_working_status_myxz = findViewById(R.id.device_working_status_myxz);
        this.device_working_status_djwz = findViewById(R.id.device_working_status_djwz);
        this.device_working_status_djdl = findViewById(R.id.device_working_status_djdl);
        this.device_working_status_gyxh = findViewById(R.id.device_working_status_gyxh);
        this.device_working_status_czsj = findViewById(R.id.device_working_status_czsj);
        this.device_button_1 = findViewById(R.id.device_button_1);
        this.device_button_2 = findViewById(R.id.device_button_2);
        this.device_button_3 = findViewById(R.id.device_button_3);
        this.device_button_4 = findViewById(R.id.device_button_4);
        this.device_button_5 = findViewById(R.id.device_button_5);

        this.device_working_status_myxz.setLabel("满溢限值");
        this.device_working_status_djwz.setLabel("电机位置");
        this.device_working_status_djdl.setLabel("电机电流");
        this.device_working_status_gyxh.setLabel("感应信号");
        this.device_working_status_czsj.setLabel("称重数据");

        this.device_working_status_myxz.setParamTag("设备运行状态_满溢限值", ParamLayout4Bean.PARAM_KEY_DEVICE_WORKING_STATUS_MYXZ);
        this.device_working_status_djwz.setParamTag("设备运行状态_电机位置", ParamLayout4Bean.PARAM_KEY_DEVICE_WORKING_STATUS_DJWZ);
        this.device_working_status_djdl.setParamTag("设备运行状态_电机电流", ParamLayout4Bean.PARAM_KEY_DEVICE_WORKING_STATUS_DJDL);
        this.device_working_status_gyxh.setParamTag("设备运行状态_感应信号", ParamLayout4Bean.PARAM_KEY_DEVICE_WORKING_STATUS_GYXH);
        this.device_working_status_czsj.setParamTag("设备运行状态_称重数据", ParamLayout4Bean.PARAM_KEY_DEVICE_WORKING_STATUS_CZSJ);

        this.device_button_1.setParamTag("设备运行状态_按钮1", ParamLayout4Bean.PARAM_KEY_DEVICE_BUTTON_1);
        this.device_button_2.setParamTag("设备运行状态_按钮2", ParamLayout4Bean.PARAM_KEY_DEVICE_BUTTON_2);
        this.device_button_3.setParamTag("设备运行状态_按钮3", ParamLayout4Bean.PARAM_KEY_DEVICE_BUTTON_3);
        this.device_button_4.setParamTag("设备运行状态_按钮4", ParamLayout4Bean.PARAM_KEY_DEVICE_BUTTON_4);
        this.device_button_5.setParamTag("设备运行状态_按钮5", ParamLayout4Bean.PARAM_KEY_DEVICE_BUTTON_5);
    }

    /**
     * 设置按钮点击事件
     *
     * @param clickEvent
     */
    public void setButtonClickEvent(ButtonClickEvent clickEvent) {
        this.device_button_1.setButtonClickEvent(clickEvent);
        this.device_button_2.setButtonClickEvent(clickEvent);
        this.device_button_3.setButtonClickEvent(clickEvent);
        this.device_button_4.setButtonClickEvent(clickEvent);
        this.device_button_5.setButtonClickEvent(clickEvent);
    }

    /**
     * 获取值
     *
     * @return 集合
     */
    public ArrayList<HashMap<String, String>> getFormValue() {
        ArrayList<HashMap<String, String>> values = new ArrayList<>();
        values.addAll(this.device_working_status_myxz.getValue());
        values.addAll(this.device_working_status_djwz.getValue());
        values.addAll(this.device_working_status_djdl.getValue());
        values.addAll(this.device_working_status_gyxh.getValue());
        values.addAll(this.device_working_status_czsj.getValue());
        return values;
    }
}
